<!doctype html>
<html lang="en">

<head>
    <script src="jquery-3.4.1.min.js"></script>
    <meta charset="UTF-8">
    <meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
          name="viewport">
    <meta content="ie=edge" http-equiv="X-UA-Compatible">
    <script src="vue.js"></script>
    <script src="bootstrap/js/bootstrap.js"></script>
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet"></link>
    <title>Task Invoke</title>
    <style>
        table {
            table-layout: auto;
        }

        table,
        td,
        th,
        tr {
            border-color: black !important;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            max-width: 600px;
            min-width: 150px;
        }

        .ID {
            width: 10%;
        }
        .excel th,.excel td{
            text-align: center;
            font-size: 13px;
            padding: 10px;
            max-width: 200px!important;
        }
    </style>
</head>

<body>
<div style="position: absolute; margin-top: -10px">
<div id="tip" class="alert alert-danger alert-dismissible fade show" style="position: fixed; width:100%;display: none; z-index: 1000">
    提示：请先获得任务ID!</div>
<div id="tipEN" class="alert alert-danger alert-dismissible fade show" style="position: fixed; width:100%;display: none; z-index: 1000">
    Hint: Please get EID first!</div>
</div>

<div class="row" style="margin-top: 40px;">

    <div class="col-md-7" id="taskInfo" style="margin:0 auto" v-if="show">
        <div id="tipCustom" class="alert alert-success alert-dismissible fade show" style="display: none; z-index: 1000">
            {{tip | lang}}</div>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel">{{"Task Invocation Instruction~执行任务说明" | lang}}</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    </div>
                    <div class="modal-body">
                        <input onkeydown="inputDelete(event)" id="serviceId" type="hidden" name="serviceId" value="-1"></input>
                        <input onkeydown="inputDelete(event)" id="url" type="hidden" name="url" value="about:blank"></input>
                        <label>{{ `Please open a terminal (For Windows, please use PowerShell instead of CMD), go to EasySpider's folder, and then copy (Command/Ctrl + c) the following command to run the task (EasySpider cannot quit when executing command, unless --read_type is set to "local"):~请在EasySpider目录下打开命令行工具Terminal （Windows请使用PowerShell而不是CMD），然后复制（Command/Ctrl + c）和运行以下命令以执行任务（执行命令时不能退出EasySpider，除非将--read_type设置为local）：` | lang }}</label>
                        <label><a href="https://github.com/NaiboWang/EasySpider/wiki/Argument-Instruction" target="_blank">{{`Click Here~点击这里` | lang}}</a> {{`Here to see argument instruction.~这里查看参数配置说明。` | lang}}</label>
                        <textarea class="form-control" style="height:150px">cd {{easyspider_location}}
{{command}} --config_folder "{{config_folder}}" --headless 0 --read_type remote --config_file_name config.json --saved_file_name </textarea>
                    </div>
                    <!-- <div class="modal-footer">
                        <button type="button" id="saveAsButton" class="btn btn-outline-primary">另存为</button>
                        <button type="button" id="saveButton" class="btn btn-primary">保存</button>
                    </div> -->
                </div>
                <!-- /.modal-content -->
            </div>
        </div>

        <div class="modal fade" id="excelModal" tabindex="-1" role="dialog" aria-labelledby="excelModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="excelModalLabel">{{"Read from Excel~从Excel文件读取输入参数" | lang}}</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    </div>
                    <div class="modal-body">
<!--                        <form action="/upload" method="post" enctype="multipart/form-data">-->
                        <div>
                        <div class="form-group" style="margin-bottom: 10px">
                            <label>{{"Please select an Excel file (.xlsx)~请选择一个Excel文件（.xlsx）" | lang}}</label>
                            <input type="file" class="form-control-file" id="excelFile" name="file">
                            <label style="display: block; margin-top:10px;margin-bottom: 0">{{fileUploadStatus | lang}}</label>
                        </div>

                            <button @click="submitFile" class="btn btn-primary" style="min-width: 100px;margin-bottom:10px">{{"Upload~上传" | lang}}</button>

<!--                        </form>-->
                        </div>
                        <label style="margin:10px 0">{{"Please design an Excel file (.xlsx) according to the following format and upload it above.~请按照以下格式设计一个Excel文件（.xlsx），并在上方上传："  | lang}}</label>
                        <table class="table table-bordered excel" style="text-align: center; font-size: 13px">
                            <thead>
                                <tr>
                                    <th scope="col">{{"Invoke Name 1~调用名称1" | lang}}</th>
                                    <th scope="col">{{"Invoke Name 2~调用名称2" | lang}}</th>
                                    <th scope="col">...</th>
                                </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>{{"Argument Value 1_1~参数值1_1" | lang}}</td>
                                <td>{{"Argument Value 2_1~参数值2_1" | lang}}</td>
                                <td>...</td>
                            </tr>
                            <tr>
                                <td>{{"Argument Value 1_1~参数值1_2" | lang}}</td>
                                <td>{{"Argument Value 2_1~参数值2_2" | lang}}</td>
                                <td>...</td>
                            </tr>
                            <tr>
                                <td>...</td>
                                <td>...</td>
                                <td>...</td>
                            </tr>
                            </tbody>
                        </table>
                        <label>{{"The 'Invoke Name' is shown at the main table of this page, such as 'urlList_0' is the invoke name of the open page operation.~“调用名称”在本页面的主表格中显示，例如“urlList_0”是“打开网页“操作的调用名称。" | lang}}</label>
                        <label>{{"You can just put part of the arguments in the Excel file, and the values of the rest of the arguments will be set to default. Example table for this task is:~您可以只在Excel文件中放入部分参数，其余参数值将被设置为默认值。一个针对此任务的表格示例为：" | lang}}</label>
                        <table class="table table-bordered excel">
                            <thead>
                                <tr>
                                    <th v-for="i in Math.min(3, task.inputParameters.length)" v-if="task.inputParameters.length>0">
                                        {{task.inputParameters[i-1]["name"]}}
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td v-for="i in Math.min(3, task.inputParameters.length)" v-if="task.inputParameters.length>0">
                                    {{getLine(i,0)}}
                                </td>
                            <tr>
                            <tr>
                                <td v-for="i in Math.min(3, task.inputParameters.length)">
                                    {{getLine(i,1)}}
                                </td>
                            <tr>
                            <tr>
                                <td v-for="i in Math.min(3, task.inputParameters.length)">
                                    <div v-if="task.inputParameters[i-1]['value'].toString().split('\n').length >=2 || task.inputParameters[i-1]['name'].indexOf('url') >=0">
                                        ...
                                    </div>
                                </td>
                            <tr>
                            </tbody>
                        </table>

                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>


        <nav aria-label="breadcrumb">
            <ol class="breadcrumb" style="padding-left:0;background-color: white">
                <li @click="gotoHome" class="breadcrumb-item"><a href="#">{{"Home~首页" | lang}}</a></li>
                <li @click="gotoInfo" aria-current="page" class="breadcrumb-item" style="color: black"><a href="#">{{"Task Information~任务信息" | lang}}</a></li>
                <li aria-current="page" class="breadcrumb-item active" style="color: black">{{"Task Invocation~任务调用"
                    | lang}}
                </li>
            </ol>
        </nav>
        <h4 style="text-align: center;">{{"Task Invocation~任务调用" | lang}}</h4>
        <p>{{"Task Name:~任务名称：" | lang}} {{task["name"]}}</p>
        <p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">{{"Task Description:~任务描述：" | lang}} {{task["desc"]}}</p>
        <p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">{{"API URL (POST):~API 调用网址（POST）：" |
            lang}} {{backEndAddressServiceWrapper}}/invokeTask?id={{task["id"]}}</p>
        <p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">{{"Click here to see how to invoke task by API via POST request (Postman or JavaScript): ~点此查看通过POST方式进行API调用的示例（Postman或JS代码）：" | lang}}<a target="_blank" href="https://github.com/NaiboWang/EasySpider/wiki/API-Invoke-Example">https://github.com/NaiboWang/EasySpider/wiki/API-Invoke-Example</a></p>
        <p><button class="btn btn-primary" @click="readFromExcel">{{"Read parameters from Excel file~从Excel文件读取输入参数"
            | lang}}
        </button></p>
        <p>{{"Please Input Parameters:~请输入参数值：" | lang}}</p>
        <form id="form">
            <table class="table table-bordered">
                <tbody>
                <tr>
                    <th style="min-width: 50px;text-align: center">ID</th>
                    <th style="text-align: center">{{"Parameter Name~参数名称" | lang}}</th>
                    <th style="text-align: center">{{"Invoke Name~调用名称" | lang}}</th>
                    <th style="text-align: center">{{"Parameter Type~参数类型" | lang}}</th>
                    <th>{{"Parameter Value~参数值（如想对多个网页执行此任务，可在“打开网页”操作内填入多行网址）" | lang}}</th>
                </tr>

                <tr v-for="i in task.inputParameters.length" v-if="task.inputParameters.length>0">
                    <td style="min-width: 50px;text-align: center">{{i}}</td>
                    <td style="max-width: 100px; text-align: center">{{task.inputParameters[i-1]["nodeName"]}}</td>
                    <td style="text-align: center">{{task.inputParameters[i-1]["name"]}}</td>
                    <td style="max-width: 100px; text-align: center">{{task.inputParameters[i-1]["type"]}}</td>
                    <td><textarea class="form-control"
                                  style="min-height: 50px;min-width: 300px;" v-bind:name="task.inputParameters[i-1]['name']"
                                  v-model="task.inputParameters[i-1]['value']"></textarea></td>
                </tr>
                </tbody>
            </table>
            <div class="form-group" style="margin-top: 10px">
                <label>{{"User Data Folder (If you want to load the cookie, data and extension(s) from your local browser, please set this folder path, and then cilck the 'Run with (Data Mode)' button to run the task):~用户本地浏览器数据目录（如果需要使用本地的登录信息，插件和cookie，请设置此目录，并点击下方“执行（带用户信息模式）”按钮开始执行任务）：" | lang}}</label>
                <input type="text" class="form-control" v-model="user_data_folder"></input>
            </div>
            <p v-if="task['cloudflare']==1">{{`要想过Cloudflare验证，需要以下目录存在115版本的Chrome Beta版浏览器，注意是Beta版不是正式版：C:\\Program Files\\Google\\Chrome Beta。如果Beta版本不是115，请在软件下载目录中找到Chrome_Beta_115_win64.7z压缩包，然后解压并复制（覆盖）为C:\\Program Files\\Google\\Chrome Beta目录即可。~To pass the Cloudflare verification, you need the following directory to exist in the 115 version of Chrome Beta, note that it is the Beta version not the official version: C:\\Program Files\\Google\\Chrome Beta,
                If the Beta version is not 115, please find the Chrome_Beta_115_win64.7z compressed package in the software download directory, then unzip and copy (overwrite) to the C:\\Program Files\\Google\\Chrome Beta directory.` | lang }}</p>
            <div class="form-group" style="margin-top: 10px" v-if="task.outputFormat=='mysql'">
                <label>{{"MySQL configuration file Path, relative to this folder:~MySQL配置文件路径，路径相对此文件夹：" | lang}} {{config_folder}}</label>
                <input type="text" class="form-control" v-model="mysql_config_path"></input>
            </div>
        </form>
        <label style="display: block">{{"Click the button below to execute the task. Long press p on the keyboard to pause the task. Manual intervention is possible during the task execution process, ~点击以下按钮执行任务，任务执行过程中可以长按p键暂停任务的执行以便" | lang }}<b>{{"~人工干预，" | lang}}</b>{{"such as manually input a password or captcha: ~如手动输入密码，验证码等。" | lang}}</label>
        <button class="btn btn-primary" v-on:click="localExecuteInstant(false)">{{"Directly Run Locally (Clean Mode)~本地直接执行（纯净模式）" |
            lang}}
        </button>
        <button class="btn btn-primary" v-on:click="localExecuteInstant(true)">{{"Directly Run Locally (Data Mode)~本地直接执行（带用户信息模式）" |
            lang}}
        </button>
        <!-- <button style="margin-left: 5px;" v-on:click="remoteExcuteInstant" class="btn btn-primary">Directly Run Remotely</button> -->
        <label style="margin-top: 15px;display: block">{{"You can also use the XPath Helper extension to test XPaths when executing the task:~执行任务的过程中也可以随时使用XPath Helper扩展来调试XPath。" | lang}}</label>
        <label style="margin-top: 15px;display: block">{{"如果想进行更复杂的操作，如设置无头模式，设置定时执行等，请使用下方的命令行执行任务选项并配置好命令行参数。~ If you want to perform more complex operations, such as setting headless mode, setting scheduled execution, etc., please use the command line to execute the task and configure the command line parameters below." | lang}}</label>
        <div style="margin-bottom: 10px;">
            <label style="margin-top: 10px;">{{"Execution ID (EID):~执行ID：" | lang}}</label>
            <input class="form-control" v-model="ID"></input>
            <p></p>
            <!-- <p>提示：点击下方按钮获得任务ID，然后根据此ID进行服务执行；也可自己POST调用接口得到ID，具体参照POST调用文档。</p> -->
            <p>{{"Hint: Click the \"Get Execution ID\" button at the bottom to get the task ID, and click the \"Execute task by commandline\" button at the back to get the prompt command on how to run this task using the command line.~提示：点击下方“获得任务执行ID”按钮得到任务ID，点击后面的“使用命令行执行任务”按钮获得如何使用命令行运行任务的提示命令。" | lang}}</p>
            <button class="btn btn-primary" href="javascript:void(0)" v-on:click="invokeTask">{{"Get Execution ID~获得任务执行ID" |
                lang}}</button>
            <button class="btn btn-primary" style="margin-left: 8px;" v-on:click="localExecute(false)">{{"Execute task by commandline (Clean Mode)~使用命令行执行任务（纯净模式）"
                | lang}}
            </button>
            <button class="btn btn-primary" style="margin-left: 8px;" v-on:click="localExecute(true)">{{"Execute task by commandline (Data Mode)~使用命令行执行任务（带用户信息模式）"
                | lang}}
            </button>
            <!-- <button v-on:click="remoteExcute" style="margin-left: 8px;" class="btn btn-primary">Run remotely</button></div> -->
        </div>

    </div>
</div>

</body>

</html>

<style>
    button{
        margin-top: 5px;
    }
</style>
<script src="global.js"></script>
<script>
    var sId = getUrlParam('id');
    var app = new Vue({
        el: '#taskInfo',
        data: {
            task: {},
            show: false, //是否渲染
            ID: "",
            tip: "The parameter values in the Excel file have been successfully imported into the corresponding field text box~Excel文件中的参数值已成功导入到对应字段文本框中",
            file:null,
            user_data_folder:"",
            fileUploadStatus: "Status: Waiting for upload~状态：等待上传",
            with_user_data: true,
            backEndAddressServiceWrapper: getUrlParam("backEndAddressServiceWrapper"),
            command: "./easyspider_executestage ",
            config_folder: "",
            easyspider_location: "",
            mysql_config_path: "",
        }, mounted() {
        $.get(this.backEndAddressServiceWrapper + "/getConfig", function (result) {
            app.$data.user_data_folder = result.user_data_folder;
            try{
                app.$data.mysql_config_path = result.mysql_config_path;
            } catch (e) {
                app.$data.mysql_config_path = "./mysql_config.json";
            }
        });
        //TODO 翻译  写清楚readme有关浏览器版本的问题  logo更换 提示看文档来运行
    },
        methods: {
            gotoHome: function () {
                let url = "";
                if (getUrlParam("lang") == "zh") {
                    url = "taskList.html?lang=zh&type="+getUrlParam("type")+"&wsport="+getUrlParam("wsport")+"&backEndAddressServiceWrapper=" + app.$data.backEndAddressServiceWrapper
                } else {
                    url = "taskList.html?lang=en&type="+getUrlParam("type")+"&wsport="+getUrlParam("wsport")+"&backEndAddressServiceWrapper=" + app.$data.backEndAddressServiceWrapper
                }
                window.location.href = url;
            }, gotoInfo: function () {
                let url = "";
                if (getUrlParam("lang") == "zh") {
                    url = "taskInfo.html?id="+getUrlParam("id")+"&lang=zh&type="+getUrlParam("type")+"&wsport="+getUrlParam("wsport")+"&backEndAddressServiceWrapper=" + app.$data.backEndAddressServiceWrapper
                } else {
                    url = "taskInfo.html?id="+getUrlParam("id")+"&lang=en&type="+getUrlParam("type")+"&wsport="+getUrlParam("wsport")+"&backEndAddressServiceWrapper=" + app.$data.backEndAddressServiceWrapper
                }
                window.location.href = url;
            }, getLine: function(i, index){
                const value = this.task.inputParameters[i-1]["value"].toString();
                const parts = value.split("\n");
                if(parts.length > index){
                    return parts[index];
                } else if(this.task.inputParameters[i-1]["name"].indexOf("url") >=0){
                    return parts[0];
                } else {
                    return "";
                }
            },
            readFromExcel: function(){
                $('#excelModal').modal('show');
            }, submitFile: function() {
                let form_data = new FormData();
                this.file = $('#excelFile').prop('files')[0];
                if(this.file == null || $('#excelFile').val() == ""){
                    this.fileUploadStatus = "Status: Please select a file~状态：请选择文件";
                    return;
                }
                if (this.file.name.split('.').pop() !== 'xlsx' ) {
                    this.fileUploadStatus = "Status: Only xlsx files are allowed!~状态：只允许上传xlsx文件！";
                    return;
                }
                // form_data.append('file', this.file);
                form_data.append('file', $('#excelFile').prop('files')[0]);
                // console.log(app.$data.backEndAddressServiceWrapper + "/excelUpload",)
                $.ajax({
                    url: app.$data.backEndAddressServiceWrapper.replace("8074","8075") + "/excelUpload",
                    type: 'POST',
                    data: form_data,
                    processData: false,
                    contentType: false,
                    success: function(response) {
                        response = JSON.parse(response);
                        $('#excelModal').modal('hide');
                        app.$data.fileUploadStatus = "Status: Upload successfully~状态：上传成功";
                        $('#excelFile').val("");
                        let inputParameters = app.$data.task.inputParameters;
                        inputParameters.forEach(function (item, index) {
                            if(Object.keys(response).includes(item.name)){
                                item.value = response[item.name].join("\r\n");
                            }
                        });
                        $("#tipCustom").slideDown(); //提示框
                        setTimeout(function() {
                            $("#tipCustom").slideUp();
                        }, 3000);
                    },
                    error: function(err) {
                        app.$data.fileUploadStatus = "Status: Upload failed~状态：上传失败";
                    }
                });
            },
            invokeTask: function () {
                let text = "";
                // if (getUrlParam("lang") == "en" || getUrlParam("lang") == "") {
                //     text = "Are you sure to get the Execution ID (EID) of current running task?";
                // } else {
                //     text = "确定要获得当前运行任务的执行ID吗？";
                // }
                // if (confirm(text)) {
                let para = {};
                let t = $('#form').serializeArray();
                t.forEach(function (item, index) {
                    para[item.name] = item.value;
                });
                let message = {
                    id: this.task.id, //这里写任务ID号，如1
                    paras: JSON.stringify(para)
                }
                $.post(app.$data.backEndAddressServiceWrapper + "/invokeTask", message, function (result) {
                    app.$data.ID = result; //得到返回的ID
                });
                // }
            },
            localExecute: function (with_user_data=false) {
                if (this.ID === "") {
                    if (getUrlParam("lang") == "en" || getUrlParam("lang") == "") {
                        $("#tipEN").slideDown(); //提示框
                        setTimeout(function() {
                            $("#tipEN").slideUp();
                        }, 3000);
                    } else {
                        $("#tip").slideDown(); //提示框
                        setTimeout(function() {
                            $("#tip").slideUp();
                        }, 3000);
                    }
                    return;
                }
                this.with_user_data = with_user_data;
                let text = "";
                // if (getUrlParam("lang") == "en" || getUrlParam("lang") == "") {
                //     text = "Are you sure to run this task locally?";
                // } else {
                //     text = "确定要在本地运行此任务吗？";
                // }
                // if (confirm(text)) {
                    let message = { //显示flowchart
                        type: 5, //消息类型，调用执行程序
                        message: {
                            "id": app.$data.ID,
                            "user_data_folder": app.$data.with_user_data ? app.$data.user_data_folder : "",
                            "mysql_config_path": app.$data.mysql_config_path,
                            "execute_type": 0,
                        }
                    };
                    ws.send(JSON.stringify(message));
                    changeCommand();
                $('#myModal').modal('show');
                // }
            },
            remoteExecute: function () {

            },
            localExecuteInstant: function (with_user_data=false) {
                let text = "";
                // if (getUrlParam("lang") == "en" || getUrlParam("lang") == "") {
                //     text = "Are you sure to run this task locally now?";
                // } else {
                //     text = "确定要立即在本地运行此任务吗？";
                // }

                this.with_user_data = with_user_data;
                // if (confirm(text)) {
                    let para = {};
                    let t = $('#form').serializeArray();
                    t.forEach(function (item, index) {
                        para[item.name] = item.value;
                    });
                    $.post(app.$data.backEndAddressServiceWrapper + "/invokeTask", {
                        id: this.task.id,
                        paras: JSON.stringify(para)
                    }, function (result) {
                        let message = { //显示flowchart
                            type: 5, //消息类型，调用执行程序
                            message: {
                                "id": result,
                                "user_data_folder": app.$data.with_user_data ? app.$data.user_data_folder : "",
                                "mysql_config_path": app.$data.mysql_config_path,
                                "execute_type": 1,
                            }
                        };
                        app.$data.ID = result;
                        ws.send(JSON.stringify(message));
                        $.get(app.$data.backEndAddressServiceWrapper + "/queryOSVersion", function (OSInfo) {
                            if(OSInfo.version == 'darwin'){
                                changeCommand();
                                $('#myModal').modal('show');
                            }
                        });
                    });
                // }
            },
            remoteExecuteInstant: function () {
            },
        }
    });

    function changeCommand() {
        $.get(app.$data.backEndAddressServiceWrapper + "/queryOSVersion", function (OSInfo) {
            if(OSInfo.version == 'win32' && OSInfo.bit == 'x64'){
                app.$data.command = "./EasySpider/resources/app/chrome_win64/easyspider_executestage.exe --id [" + app.$data.ID.toString() + "] --user_data " + (app.$data.with_user_data ? "1" : "0") + " --server_address " + app.$data.backEndAddressServiceWrapper;
            } else if(OSInfo.version == 'win32' && OSInfo.bit == 'ia32'){
                app.$data.command = "./EasySpider/resources/app/chrome_win32/easyspider_executestage.exe --id [" + app.$data.ID.toString() + "] --user_data " + (app.$data.with_user_data ? "1" : "0") + " --server_address " + app.$data.backEndAddressServiceWrapper;
            } else if(OSInfo.version == 'linux'){
                app.$data.command = "./EasySpider/resources/app/chrome_linux64/easyspider_executestage --id '[" + app.$data.ID.toString() + "]' --user_data " + (app.$data.with_user_data ? "1" : "0") + " --server_address " + app.$data.backEndAddressServiceWrapper;
            } else if(OSInfo.version == 'darwin'){
                if(getUrlParam("lang") == "zh"){
                    app.$data.easyspider_location = "你的EasySpider文件夹，如：cd /Users/"+ app.$data.config_folder.split("/")[2] + "/Downloads/EasySpider_MacOS_all_arch";
                } else {
                    app.$data.easyspider_location = "Your EasySpider folder, such as: cd /Users/"+ app.$data.config_folder.split("/")[2] + "/Downloads/EasySpider_MacOS_all_arch";
                }
                app.$data.command = "./easyspider_executestage --id '[" + app.$data.ID.toString() + "]' --user_data " + (app.$data.with_user_data ? "1" : "0") + " --server_address " + app.$data.backEndAddressServiceWrapper;
            }
        });
    }

    $.get(app.$data.backEndAddressServiceWrapper + "/queryTask?id=" + sId, function (result) {
        app.$data.task = result;
        app.$data.show = true;
    });

    ws = new WebSocket("ws://localhost:"+getUrlParam("wsport"));
    ws.onopen = function () {
        // Web Socket 已连接上，使用 send() 方法发送数据
        console.log("Connected");
        let message = {
            type: 0, //消息类型，0代表链接操作
            message: {
                id: 1, //socket id
            }
        };
        this.send(JSON.stringify(message));
        message = { //显示flowchart
            type: 5, //消息类型，调用执行程序
            message: {
                "id": -1,
                "user_data_folder": "",
                "mysql_config_path": "-1",
                "execute_type": 1,
            }
        };
        this.send(JSON.stringify(message));
    };
    ws.onmessage = function(message){
        message = JSON.parse(message.data);
        app.$data.config_folder = message.config_folder.replaceAll("\\","/");
        app.$data.easyspider_location = message.easyspider_location.replace("/EasySpider.app/","");
    }
    ws.onclose = function () {
        // 关闭 websocket
        console.log("连接已关闭...");
    };
</script>
